package controllers

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"week3/models/mysql"
	"week3/models/request"
)

// 新增
func CreateKe(c *gin.Context) {
	var data request.ShopKeRequest
	if err := c.ShouldBindJSON(&data); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	ke := mysql.CreateKe(data)
	if ke == false {
		c.JSON(http.StatusInternalServerError, gin.H{
			"code": 500,
			"msg":  "新增失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "新增成功",
	})

}

// 列表查询
func KeList(c *gin.Context) {
	var data request.KeListRequest
	if err := c.ShouldBindJSON(&data); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	list := mysql.KeList(data)
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"list": list,
	})
}

// 联查
func GetKeDetail(c *gin.Context) {
	list := mysql.GetKeDetail()
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"list": list,
	})
}
